package cn.gpnu.web.servlet;

import cn.gpnu.dao.TreePriceDao;
import cn.gpnu.dao.Treedao;
import cn.gpnu.dao.Userdao;
import cn.gpnu.domain.Tree;
import cn.gpnu.domain.TreePrice;
import cn.gpnu.domain.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/usetree_servlet")
public class usetree_servlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int user_id = Integer.parseInt(req.getParameter("user_id"));
        int tree_id = Integer.parseInt(req.getParameter("tree_id"));
        Userdao userdao = new Userdao();
        User user = userdao.select_user(user_id);

        userdao.choose_tree(user_id,tree_id);

        req.setAttribute("user",user);
//        req.getRequestDispatcher("/time.jsp").forward(req,resp);
        this.getServletContext().getRequestDispatcher("/JSP/time.jsp").forward(req, resp);
    }
}
